package com.evil.DAO;

import com.evil.Bean.FlowCallbackBean;
import com.evil.DB_Utils.DB_Utils;

import java.util.ArrayList;

/********************************************
 * 工程名：Web
 * 包名：com.evil.DAO
 * 时间：16-9-24 上午10:44
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：流量兑换记录DAO
 ********************************************/
public class FlowCallbackDAO
{
    private ArrayList<FlowCallbackBean> flowCallbackBeanList;


    /**
     * 根据用户手机获得所以流量兑换记录
     *
     * @param phone
     */
    public ArrayList<FlowCallbackBean> getAllList(String phone)
    {
        final String url = "SELECT\n" +
                "flowcallback.id,\n" +
                "flowcallback.phone,\n" +
                "flowcallback.flow,\n" +
                "flowcallback.type,\n" +
                "flowcallback.datetime,\n" +
                "flowcallback.state,\n" +
                "flowcallback.remarks\n" +
                "FROM\n" +
                "flowcallback\n" +
                "WHERE\n" +
                "flowcallback.phone = ?";

        flowCallbackBeanList = new ArrayList<>();

        DB_Utils.query(url).add(phone).build().getAll(next ->
        {
            FlowCallbackBean bean = new FlowCallbackBean();
            bean.setId(next.getInt(1));
            bean.setPhone(next.getString(2));
            bean.setFlow(next.getInt(3));
            bean.setType(next.getString(4));
            bean.setDatetime(next.getDateTime(5));
            bean.setState(next.getString(6));
            bean.setRemarks(next.getString(7));
            flowCallbackBeanList.add(bean);
        }).close();

        return flowCallbackBeanList;
    }
}
